﻿using AntdUI;
using Super.Admin.IServices;
using Super.Admin.Mappers;
using Super.Admin.Models;
using Super.Admin.Models.Permission;
using Super.Admin.Utils;
using Super.Admin.Utils.EventAggregator.EventType;
using Super.Admin.Utils.EventAggregator;
using Super.Admin.Utils.ThemeManager;
using Super.Admin.Views.Main;
using System.Data;
using BaseForm = Super.Admin.Views.Base.BaseForm;
using Super.Admin.Assets.CustomControl;
using System.Diagnostics.Metrics;
using TabPage = AntdUI.TabPage;
using Super.Admin.Global;
using System.Diagnostics;
using Super.Admin.Views.Base;
using Autofac;

namespace Super.Admin.Views
{
    public partial class FrmMain : BaseForm
    {
        private readonly IPermissionService _permissionService;

        private PermissionBaseModel _homeMneu; // 工作台 或者首页 必须Id == 20001
        public List<PermissionBaseModel> AllPermissionList { get; set; } = new List<PermissionBaseModel>();  // 暂存 Molde形式的 所有 Permission 集合 
        public List<PermissionBaseModel> AllMenuModelList = new List<PermissionBaseModel>(); // 暂存 Molde形式的 所有 Menu 集合 
        public List<PermissionBaseModel> MenuList { get; set; } = new List<PermissionBaseModel>(); // 菜单列表
        public List<TabItemModel> TabItemModelList { get; set; } = new List<TabItemModel>(); // Tab页列表
        private Dictionary<Keys, Action> _shortcutActions = new Dictionary<Keys, Action>(); // 快捷键

        #region 控件
        private UcMainDrawerSetting _ucMainDrawerSetting; // 设置抽屉
        private UcSuperTitle _ucSuperTitle; // 标题控件
        private GridPanel _gridMain; // 主面板
        private AntdUI.Menu _treeMenu; // 树形菜单控件 
        private AntdUI.Breadcrumb _breadcrumbMenu; // 面包屑导航控件
        private AntdUI.Tabs _tabMain; // 主Tab控件
        private AntdUI.GridPanel _gridSildebar; // 侧边栏网格
        private AntdUI.Panel _pnlSildebar; // 侧边栏面板
        private AntdUI.Panel _pnlTopBar; // 顶部面板
        private AntdUI.Panel _pnlContent; // 主内容
        private AntdUI.Input _txtSearch; // 搜索输入框
        private AntdUI.Avatar _avatar; // 头像控件
        private AntdUI.Button _btnSearch; // 搜索按钮
        private AntdUI.Button _btnCollapseTreeMenu; // 折叠树形菜单按钮
        private AntdUI.Button _btnRefresh; // 刷新按钮
        private AntdUI.Button _btnSetting; // 设置按钮
        private AntdUI.Button _btnSwithTheme; // 切换主题按钮
        private AntdUI.Button _btnMessage; // 消息通知按钮
        private AntdUI.Dropdown _btnSwitchLanguage; // 语言切换按钮
        private AntdUI.Segmented _btnSilderSwitchMenu; // 侧边菜单按钮 菜单切换按钮
        private AntdUI.Label _lblLogoTitle;// logo标题控件
        private AntdUI.Menu _treeSencondMenu; // 双列菜单 - 二级菜单
        private AntdUI.Panel _pnlSencondMenu; // 双列菜单 - 二级菜单面板
        private CenterPanel _pnlTopMenuCenter; // 顶部菜单
        private AntdUI.Panel _pnlTopBtnPanel; // 顶部按钮面板
        private AntdUI.Segmented _btnSwitchTopFirstMenu; // 顶部菜单按钮面板 混合双列时使用
        private AntdUI.Segmented _btnSilderSwitchSecondMenu; // 侧边二级菜单按钮面板 混合双列时使用
        private AntdUI.Menu _treeThirdMenu; // 侧边三级菜单 混合双列时使用
        private AntdUI.Panel _pnlThirdMenu; // 侧边三级菜单按钮面板 - 混合双列时使用
        private AntdUI.FormFloatButton _btnSettingfloat; // 悬浮的设置按钮
        private AntdUI.Button _btnHome; // 切换主题按钮
        private AntdUI.Label _lblBottomBarContent; // 底栏内容
        #endregion

        // 侧边菜单距离
        private string _silderVerticalWidth = "220"; // 菜单垂直时候的宽度
        private string _silderOnlyMentBtn = "100"; // 收起菜单 只有图标 按钮
        private string _silderSecondColumn = "180"; // 第二次菜单 例如双列菜单和混合双列
        private string _silderWidth = "220"; // 侧边栏宽度
        private bool _isCollapseTreeMenu = false; // 是否折叠菜单

        public FrmMain(IPermissionService permissionService)
        {
            InitializeComponent();
            InitializeControls(); // 初始化控件
            SetMainLayout(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition); // 初始化布局
            this.Load += FrmMain_Load;
            _permissionService = permissionService;
        }

        private void FrmMain_Load(object? sender, EventArgs e)
        {
            LoadLocalPermissionList(); // 加载本地权限列表
            InitBtnSettingFloat(); // 初始化设置悬浮 
            InitHomePage(); // 初始化首页
            Global.AppContext.Instance.EventTokenList.Add(EventAggregator.Default.Subscribe<AppearanceSettingEvent>(DoModifyAppearanceSetting));
            Global.AppContext.Instance.EventTokenList.Add(EventAggregator.Default.Subscribe<LayoutSettingEvent>(DoModifyLayoutSetting));
            Global.AppContext.Instance.EventTokenList.Add(EventAggregator.Default.Subscribe<ShortcutSettingEvent>(DoModifyShortcutSetting));
            Global.AppContext.Instance.EventTokenList.Add(EventAggregator.Default.Subscribe<GeneralSettingEvent>(DoModifyGeneralSetting));
        }

        private void DoModifyGeneralSetting(GeneralSettingEvent @event)
        {
            switch (@event.Type)
            {
                case GeneralSettingEvent.GeneralSettingType.SwitchLanguage:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language = (LanguageType)@event.Value;
                    SetLanguageMode();
                    break;
                case GeneralSettingEvent.GeneralSettingType.AnimationEnablement:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.AnimationEnablement = (bool)@event.Value;
                    SetAnimationEnablement((bool)@event.Value);
                    break;
                case GeneralSettingEvent.GeneralSettingType.ShadowEnablement:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ShadowEnablement = (bool)@event.Value;
                    SetShadowEnablement((bool)@event.Value);
                    break;
                case GeneralSettingEvent.GeneralSettingType.ScrollBarHiddenStyle:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ScrollBarHiddenStyle = (bool)@event.Value;
                    SetScrollBarHiddenStyle((bool)@event.Value);
                    break;
                case GeneralSettingEvent.GeneralSettingType.RegularlyCheckForUpdates:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.RegularlyCheckForUpdates = (bool)@event.Value;
                    break;
                case GeneralSettingEvent.GeneralSettingType.HighQualityPresentationOfText:
                    ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.HighQualityPresentationOfText = (bool)@event.Value;
                    SetHighQualityPresentationOfText((bool)@event.Value);
                    break;
            }
        }

        private void SetAnimationEnablement(bool value) => AntdUI.Config.Animation = value;
        private void SetShadowEnablement(bool value) => AntdUI.Config.ShadowEnabled = value;
        private void SetScrollBarHiddenStyle(bool value) => AntdUI.Config.ScrollBarHide = value;
        private void SetHighQualityPresentationOfText(bool value)
        {
            if (AntdUI.Config.TextRenderingHighQuality == value) return;
            AntdUI.Config.TextRenderingHighQuality = value;
            Refresh();
        }

        private void DoModifyShortcutSetting(ShortcutSettingEvent @event)
        {
            switch (@event.Type)
            {
                case ShortcutSettingEvent.ShortcutSettingType.EnableGlobalShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable = (bool)@event.Value;
                    break;
                case ShortcutSettingEvent.ShortcutSettingType.EnableGlobalSearchShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.GlobalSearch.EnableShortcut = (bool)@event.Value;
                    break;
                case ShortcutSettingEvent.ShortcutSettingType.EnableLogoutShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Logout.EnableShortcut = (bool)@event.Value;
                    break;
                case ShortcutSettingEvent.ShortcutSettingType.EnableLockScreenShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.LockScreen.EnableShortcut = (bool)@event.Value;
                    break;
                case ShortcutSettingEvent.ShortcutSettingType.EnableRefreshViewShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.RefreshView.EnableShortcut = (bool)@event.Value;
                    break;
                case ShortcutSettingEvent.ShortcutSettingType.EnableFullScreenShortcut:
                    ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.FullScreen.EnableShortcut = (bool)@event.Value;
                    break;
            }
        }

        private void InitBtnSettingFloat()
        {
            _btnSettingfloat = AntdUI.FloatButton.open(this, new FloatButton.ConfigBtn[]
            {
                    new AntdUI.FloatButton.ConfigBtn("", "Admin.Setting", true)
                    {
                                Tooltip = "偏好设置",
                                Type= AntdUI.TTypeMini.Primary
                    }
            }, btn =>
            {
                if (_ucMainDrawerSetting == null || _ucMainDrawerSetting.IsDisposed)
                    _btnSetting_Click(_btnSetting, EventArgs.Empty);
            });
            SetDisplayTopBar(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.TopBar.DisplayTopBar); // 设置是否显示顶栏
        }

        private void InitializeThemeSetting()
        {
            // 先刷新一下主题 再现有的主题上修改某些颜色
            this.SuspendLayout();

            #region 外观
            this.RefreshTheme(this, ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType);
            if (ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType == TAMode.Light)
            {
                // DarkSidebar 
                if (ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.DarkSidebar)
                {
                    ThemeSettingHelper.Instance.SetControlsTheme(_gridSildebar, TAMode.Dark);
                }
                else
                {
                    ThemeSettingHelper.Instance.SetControlsTheme(_gridSildebar, TAMode.Light);
                }
                // DarkTopBar
                if (ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.DarkTopBar)
                {
                    ThemeSettingHelper.Instance.SetControlsTheme(_pnlTopBar, TAMode.Dark);
                }
                else
                {
                    ThemeSettingHelper.Instance.SetControlsTheme(_pnlTopBar, TAMode.Light);
                }
            }
            #endregion

            #region 布局

            SetDisplaySidebar(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.DisplaySidebar); // 设置是否显示侧边栏
            SetCollapseMenu(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.CollapseMenu); // 设置是否折叠菜单
            SetMenuBarWidth(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.MenuBarWidth); // 设置菜单宽度
            SetAccordionMenu(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.AccordionMenu); // 设置是否手风琴菜单
            SetEnableBreadcrumbNavigation(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.EnableBreadcrumbNavigation); // 设置开启面包屑导航
            InitializeBtnSetThemeIconSvg();
            SetDisplayHomepageButton(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.DisplayHomepageButton); // 是否显示首页图标
            SetEnableTabBar(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.EnableTabBar); // 是否显示Tabs头
            SetStartDragAndDropSorting(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.StartDragAndDropSorting); // 是否启用拖拽排序
            SetTabMoreButtonStyle(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.TabMoreButtonStyle); // 设置Tab更多按钮样式
            SetLabelStyle(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.LabelStyle); // 设置标签风格
            SetEnableGlobalSearch(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableGlobalSearch); // 启用全局搜索
            SetEnableThemeSwitch(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableThemeSwitch); // 启用主题切换
            SetEnableLanguageSwitching(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableLanguageSwitching); // 启用语言切换
            SetEnableNotification(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableNotification); // 启用通知
            SetEnableSidebarSwitch(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableSidebarSwitch); // 启用侧边栏切换
            SetStartRefreshing(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.StartRefreshing); // 启用刷新
            SetEnableTheBottomBar(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.BottomBar.EnableTheBottomBar); // 启用底栏
            SetBottomBarContent(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.BottomBar.BottomBarContent); // 底栏内容






            #endregion

            LoadShortcuts(); // 快捷键

            #region 通用
            SetAnimationEnablement(ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.AnimationEnablement);
            SetShadowEnablement(ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ShadowEnablement);
            SetScrollBarHiddenStyle(ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ScrollBarHiddenStyle);
            SetHighQualityPresentationOfText(ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.HighQualityPresentationOfText);
            #endregion

            this.ResumeLayout();
        }

        private void InitializeBtnSetThemeIconSvg()
        {
            _btnSwithTheme.IconSvg = ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType == TAMode.Light
                ? "Admin.DarkThemes"
                : "Admin.LightThemes";
        }

        // 设置
        private void DoModifyAppearanceSetting(AppearanceSettingEvent @event)
        {
            switch (@event.Type)
            {
                case AppearanceSettingEvent.AppearanceSettingType.ThemeType:
                    ThemeSettingHelper.Instance.SwitchThemeDrakOrLight((AntdUI.TAMode)@event.Value);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.DarkSidebar:
                    ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.DarkSidebar = (bool)@event.Value;
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.DarkTopBar:
                    ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.DarkTopBar = (bool)@event.Value;
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.PrimaryColor:
                    ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Primary, (string)@event.Value);
                    _btnSilderSwitchMenu.BackActive = ColorTranslator.FromHtml(ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.BuiltInThemes.PrimaryColor);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.WarningColor:
                    ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Warning, (string)@event.Value);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.InfoColor:
                    ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Info, (string)@event.Value);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.ErrorColor:
                    ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Error, (string)@event.Value);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.SuccessColor:
                    ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Success, (string)@event.Value);
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.ResetPreferenceSettings:
                    DoResetPreferenceSettings();
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.CopyPreferenceSettings:
                    DoCopyPreferenceSettings();
                    break;
                case AppearanceSettingEvent.AppearanceSettingType.ClearCacheAndLogout:
                    DoClearCacheAndLogout();
                    break;
            }
            InitializeThemeSetting();
        }

        // 清除缓存 退出登录
        private void DoClearCacheAndLogout()
        {
            var result = AntdUI.Modal.open(this, "提示", "是否要清除缓存并退出登录");
            if (result == DialogResult.OK)
            {
                File.Delete(FilePath.ThemeSettingFilePath);
                ThemeSettingHelper.Instance.ApplyTheme();
                ResetApplication();
            }
        }

        // 重启
        private void ResetApplication()
        {
            // 重启当前程序
            Process.Start(Environment.ProcessPath ?? System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            Application.Exit();
        }

        // 复制参数
        private void DoCopyPreferenceSettings()
        {
            FileHelper.CopyFiles(new string[] { FilePath.ThemeSettingFilePath });
            AntdUI.Message.success(this, $"复制成功，请在 app 下的【bin{FilePath.ThemeSettingFilePath.Split("bin")[1]}】内进行覆盖");
        }

        private void DoResetPreferenceSettings()
        {
            var result = AntdUI.Modal.open(this, "提示", "是否要清除缓存");
            if (result == DialogResult.OK)
            {
                File.Delete(FilePath.ThemeSettingFilePath); // 删除配置文件
                ThemeSettingHelper.Instance.ApplyTheme(); // 应用配置参数 如果没有配置文件 则默认参数
                InitializeControls(); // 初始化控件
                SetMainLayout(ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition); // 初始化布局
                LoadLocalPermissionList(); // 加载本地权限列表
                InitBtnSettingFloat(); // 初始化设置悬浮 
                InitHomePage(); // 初始化首页
            }
        }

        private void DoModifyLayoutSetting(LayoutSettingEvent @event)
        {
            switch (@event.Type)
            {
                case LayoutSettingEvent.LayoutSettingType.NavigationPosition:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition = (NavigationPosition)@event.Value;
                    SetMainLayout((NavigationPosition)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.ShowSidebar:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.DisplaySidebar = (bool)@event.Value;
                    SetDisplaySidebar((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.CollapseMenu:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.CollapseMenu = (bool)@event.Value;
                    SetCollapseMenu((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.AccordionMenu:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.AccordionMenu = (bool)@event.Value;
                    SetAccordionMenu((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.MenuBarWidth:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Sidebar.MenuBarWidth = (int)@event.Value;
                    SetMenuBarWidth((int)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.DisplayTopBar:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.TopBar.DisplayTopBar = (bool)@event.Value;
                    SetDisplayTopBar((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableBreadcrumbNavigation:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.EnableBreadcrumbNavigation = (bool)@event.Value;
                    SetEnableBreadcrumbNavigation((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.DisplayBreadcrumbIcon:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.DisplayBreadcrumbIcon = (bool)@event.Value;
                    SetDisplayBreadcrumbIcon((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.DisplayHomepageButton:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.DisplayHomepageButton = (bool)@event.Value;
                    SetDisplayHomepageButton((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableTabBar:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.EnableTabBar = (bool)@event.Value;
                    SetEnableTabBar((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.MaximumNumberOfTagPages:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.MaximumNumberOfTagPages = (int)@event.Value;
                    break;
                case LayoutSettingEvent.LayoutSettingType.StartDragAndDropSorting:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.StartDragAndDropSorting = (bool)@event.Value;
                    SetStartDragAndDropSorting((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.TabMoreButtonStyle:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.TabMoreButtonStyle = (TabTypExceed)@event.Value;
                    SetTabMoreButtonStyle((TabTypExceed)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.LabelStyle:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.LabelStyle = (LabelStyleType)@event.Value;
                    SetLabelStyle((LabelStyleType)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableGlobalSearch:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableGlobalSearch = (bool)@event.Value;
                    SetEnableGlobalSearch((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableThemeSwitch:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableThemeSwitch = (bool)@event.Value;
                    SetEnableThemeSwitch((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableLanguageSwitching:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableLanguageSwitching = (bool)@event.Value;
                    SetEnableLanguageSwitching((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableNotification:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableNotification = (bool)@event.Value;
                    SetEnableNotification((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableLockScreen:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableLockScreen = (bool)@event.Value;
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableSidebarSwitch:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.EnableSidebarSwitch = (bool)@event.Value;
                    SetEnableSidebarSwitch((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.StartRefreshing:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.StartRefreshing = (bool)@event.Value;
                    SetStartRefreshing((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.PreferredLocationSettings:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.SmallComponents.PreferredLocationSettings = (PreferredLocationSettingsType)@event.Value;
                    SetPreferredLocationSettings((PreferredLocationSettingsType)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.EnableTheBottomBar:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.BottomBar.EnableTheBottomBar = (bool)@event.Value;
                    SetEnableTheBottomBar((bool)@event.Value);
                    break;
                case LayoutSettingEvent.LayoutSettingType.BottomBarContent:
                    ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.BottomBar.BottomBarContent = (string)@event.Value;
                    SetBottomBarContent((string)@event.Value);
                    break;
            }
        }

        // 快捷键设置
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)
        {
            if (_shortcutActions.ContainsKey(keyData))
            {
                _shortcutActions[keyData]();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        // 加载快捷键
        private void LoadShortcuts()
        {
            _shortcutActions[ParseKeys(ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.GlobalSearch.ShortcutKeysText)] = DoGlobalSearch; // 全局搜索
            _shortcutActions[ParseKeys(ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Logout.ShortcutKeysText)] = DoLogout; // 退出登录
            _shortcutActions[ParseKeys(ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.LockScreen.ShortcutKeysText)] = DoLockScreen; // 锁定屏幕
            _shortcutActions[ParseKeys(ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.RefreshView.ShortcutKeysText)] = DoRefreshView; // 刷新
            _shortcutActions[ParseKeys(ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.FullScreen.ShortcutKeysText)] = DoFullScreen; // 全屏
        }

        private void DoFullScreen()
        {
            if (!ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable || !ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.FullScreen.EnableShortcut) return;
            AntdUI.Message.success(this, "全屏");
        }

        private void DoLockScreen()
        {
            if (!ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable || !ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.LockScreen.EnableShortcut) return;
            Utils.Win32.Win32.LockScreen();
        }

        private void DoRefreshView()
        {
            if (!ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable || !ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.RefreshView.EnableShortcut) return;
            (_tabMain.Pages[_tabMain.SelectedIndex].Controls[0] as BaseUserControl).DoRefresh();
        }

        private void DoLogout()
        {
            if (!ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable || !ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Logout.EnableShortcut) return;
            AntdUI.Message.success(this, "退出登录");
        }

        private void DoGlobalSearch()
        {
            if (!ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable || !ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.GlobalSearch.EnableShortcut) return;
            AntdUI.Message.success(this, "全局搜索");
        }

        // string 处理成快捷键
        private static Keys ParseKeys(string keysString)
        {
            Keys result = Keys.None;
            if (string.IsNullOrEmpty(keysString)) return result;
            string[] parts = keysString.Split('+');
            foreach (string part in parts)
            {
                string trimmedPart = part.Trim();
                // 处理修饰键
                if (trimmedPart.Equals("Control") || trimmedPart.Equals("Ctrl", StringComparison.OrdinalIgnoreCase))
                {
                    result |= Keys.Control;
                }
                else if (trimmedPart.Equals("Alt", StringComparison.OrdinalIgnoreCase))
                {
                    result |= Keys.Alt;
                }
                else if (trimmedPart.Equals("Shift", StringComparison.OrdinalIgnoreCase))
                {
                    result |= Keys.Shift;
                }
                else
                {
                    // 处理普通键
                    try
                    {
                        Keys key = (Keys)Enum.Parse(typeof(Keys), trimmedPart, true);
                        result |= key;
                    }
                    catch { }
                }
            }
            return result;
        }

        // 设置底栏内容
        private void SetBottomBarContent(string value) => _lblBottomBarContent.Text = value;
        // 启用底栏
        private void SetEnableTheBottomBar(bool value) => _lblBottomBarContent.Visible = value;
        // 偏好设置位置
        private void SetPreferredLocationSettings(PreferredLocationSettingsType value)
        {
            switch (value)
            {
                case PreferredLocationSettingsType.Automatic:
                case PreferredLocationSettingsType.TopBar:
                    _btnSetting.Visible = true;
                    _btnSettingfloat.Visible = false;
                    break;
                case PreferredLocationSettingsType.Fixed:
                    _btnSettingfloat.Visible = true;
                    _btnSetting.Visible = false;
                    break;
            }
        }
        // 启用刷新
        private void SetStartRefreshing(bool value) => _btnRefresh.Visible = value;
        // 启用侧边栏切换
        private void SetEnableSidebarSwitch(bool value) => _btnCollapseTreeMenu.Visible = value;
        // 启用通知
        private void SetEnableNotification(bool value) => _btnMessage.Visible = value;
        // 启用语言切换
        private void SetEnableLanguageSwitching(bool value) => _btnSwitchLanguage.Visible = value;
        // 启用主题切换
        private void SetEnableThemeSwitch(bool value) => _btnSwithTheme.Visible = value;
        // 启用全局搜索
        private void SetEnableGlobalSearch(bool value)
        {
            _txtSearch.Visible = value;
            _btnSearch.Visible = value;
        }

        // 设置Tab的标签风格
        private void SetLabelStyle(LabelStyleType value)
        {
            switch (value)
            {
                case LabelStyleType.Line:
                    _tabMain.Style = new AntdUI.Tabs.StyleLine() { };
                    break;
                case LabelStyleType.Card:
                    _tabMain.Style = new AntdUI.Tabs.StyleCard() { Closable = true };
                    break;
                case LabelStyleType.Brisk:
                    _tabMain.Style = new AntdUI.Tabs.StyleCard2() { Closable = AntdUI.Tabs.StyleCard2.CloseType.activate };
                    break;
            }
            // 把所有的移除 再插入 强制刷新
            var pages = _tabMain.Pages.ToList();
            _tabMain.Pages.Clear();
            _tabMain.Pages.AddRange(pages);
        }

        // 设置Tab更多按钮样式
        private void SetTabMoreButtonStyle(TabTypExceed value) => _tabMain.TypExceed = value;
        // 启用拖拽排序
        private void SetStartDragAndDropSorting(bool value) => _tabMain.DragOrder = value;
        // 是否显示Tabs头
        private void SetEnableTabBar(bool value) => _tabMain.TabMenuVisible = value;
        // 是否显示首页按钮
        private void SetDisplayHomepageButton(bool value) => _btnHome.Visible = value;
        // 面包屑图标
        private void SetDisplayBreadcrumbIcon(bool value)
        {
            _breadcrumbMenu.Items.Clear();
            SetBreadcrumb((_tabMain.Pages[_tabMain.SelectedIndex].Tag as PermissionBaseModel).Id);
        }
        // 开启面包屑导航
        private void SetEnableBreadcrumbNavigation(bool value) => _breadcrumbMenu.Visible = value;
        // 设置手风琴菜单
        private void SetAccordionMenu(bool value) => _treeMenu.Unique = value;

        // 是否显示顶栏
        private void SetDisplayTopBar(bool value)
        {
            _pnlTopBar.Visible = value;
            if (!value)
            {
                // 设置悬浮按钮
                _btnSettingfloat.Visible = true;
            }
            else
            {
                _btnSettingfloat.Visible = false;
            }
        }

        // 设置菜单宽度
        private void SetMenuBarWidth(int value)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition != NavigationPosition.SideMenu) return;
            if (_silderWidth == _silderVerticalWidth)
            {
                _silderVerticalWidth = value + "";
                _silderWidth = _silderVerticalWidth;
                _gridMain.Span = _silderWidth + " 100%";
            }
        }

        // 设置折叠菜单
        private void SetCollapseMenu(bool value)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition != NavigationPosition.SideMenu) return;
            if (value)
            {
                // 设置菜单的宽度
                // 收起所有菜单
                CollapseAllMenu(null);
                _treeMenu.Collapsed = true;
                _ucSuperTitle.ShowTitle = false;
                _gridMain.Span = _silderOnlyMentBtn + " 100%";
                _silderWidth = _silderOnlyMentBtn;
            }
            else
            {
                // 设置菜单的宽度
                _treeMenu.Collapsed = false;
                _ucSuperTitle.ShowTitle = true;
                _gridMain.Span = _silderVerticalWidth + " 100%";
                _silderWidth = _silderVerticalWidth;
            }
        }

        // 收起所有菜单
        private void CollapseAllMenu(MenuItemCollection items)
        {
            if (items == null)
            {
                items = _treeMenu.Items;
            }
            foreach (var item in items)
            {
                item.Expand = false;
                if (item.Sub.Count() > 0)
                {
                    CollapseAllMenu(item.Sub);
                }
            }
        }

        // 设置折叠左侧菜单栏
        private void SetDisplaySidebar(bool value)
        {
            if (value && _isCollapseTreeMenu)
            {
                _btnCollapseTreeMenu_Click(_btnCollapseTreeMenu, EventArgs.Empty);
            }
            else if (!value && !_isCollapseTreeMenu)
            {
                _btnCollapseTreeMenu_Click(_btnCollapseTreeMenu, EventArgs.Empty);
            }
        }


        private void SetMainLayout(NavigationPosition navigation)
        {
            this.SuspendLayout();
            InitializeMainLayout(); // 初始化主布局 // 清空布局
            switch (navigation)
            {
                case NavigationPosition.SideMenu:
                    _silderWidth = _silderVerticalWidth;
                    SetMainLayoutSideVerticalMenu();
                    break;
                case NavigationPosition.VerticalDoubleColumnMenu:
                    _silderWidth = _silderOnlyMentBtn;
                    SetMainLayoutVerticalDoubleColumnMenu();
                    break;
                case NavigationPosition.HorizontalMenu:
                    _silderWidth = "0";
                    SetMainLayoutHorizontalMenu();
                    break;
                case NavigationPosition.MixedDoubleColumnMenu:
                    _silderWidth = _silderOnlyMentBtn;
                    SetMixedDoubleCoulumnMenu();
                    break;
            }
            InitializeThemeSetting();
            this.ResumeLayout();
        }

        private void SetMixedDoubleCoulumnMenu()
        {
            _gridMain.Span = _silderWidth + " 100%";

            _pnlContent.Controls.Add(_tabMain);

            // 顶部 中间
            _pnlTopBtnPanel.Controls.Add(_btnSwitchTopFirstMenu);

            // 左侧
            _btnRefresh.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnRefresh);
            _btnCollapseTreeMenu.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnCollapseTreeMenu);

            // 右侧
            _txtSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_txtSearch);
            _btnSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSearch);
            _btnSetting.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSetting);
            _btnSwithTheme.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwithTheme);
            _btnSwitchLanguage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwitchLanguage);
            _btnMessage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnMessage);
            _avatar.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_avatar);
            _pnlTopBar.Controls.Add(_pnlTopBtnPanel);

            _pnlContent.Controls.Add(_pnlTopBar);
            _gridMain.Controls.Add(_pnlContent);

            // 侧边栏
            _pnlSildebar.Controls.Add(_btnSilderSwitchSecondMenu);
            _ucSuperTitle.Dock = DockStyle.Top;
            _ucSuperTitle.ShowTitle = false;
            _pnlSildebar.Controls.Add(_ucSuperTitle);
            _gridSildebar.Span = "100%";
            _gridSildebar.Controls.Add(_pnlSildebar);
            _gridMain.Controls.Add(_gridSildebar);

            // 切换一下二级菜单
            _btnSwitchTopFirstMenu_SelectIndexChanged(_btnSwitchTopFirstMenu, new IntEventArgs(_btnSwitchTopFirstMenu.SelectIndex));
        }

        private void SetMainLayoutHorizontalMenu()
        {
            _gridMain.Span = "100%";

            _pnlContent.Controls.Add(_tabMain);

            // 顶部 中间
            _treeMenu.Size = new Size(800, 40);
            _treeMenu.Dock = DockStyle.None;
            _treeMenu.Gap = 20;
            _treeMenu.Collapsed = false;
            _treeMenu.Mode = TMenuMode.Horizontal;
            _pnlTopMenuCenter.Controls.Add(_treeMenu);
            _pnlTopBtnPanel.Controls.Add(_pnlTopMenuCenter);

            // 左侧
            _btnRefresh.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnRefresh);

            // 右侧
            _txtSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_txtSearch);
            _btnSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSearch);
            _btnSetting.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSetting);
            _btnSwithTheme.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwithTheme);
            _btnSwitchLanguage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwitchLanguage);
            _btnMessage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnMessage);
            _avatar.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_avatar);
            _pnlTopBar.Controls.Add(_pnlTopBtnPanel);

            // 标题
            _ucSuperTitle.Dock = DockStyle.Left;
            _ucSuperTitle.ShowTitle = true;
            _pnlTopBar.Controls.Add(_ucSuperTitle);
            _pnlContent.Controls.Add(_pnlTopBar);
            _pnlContent.Controls.Add(_lblBottomBarContent);

            _gridMain.Controls.Add(_pnlContent);
        }

        private void SetMainLayoutVerticalDoubleColumnMenu()
        {
            _gridMain.Span = _silderWidth + " 100%";

            // 内容区域
            _pnlContent.Controls.Add(_tabMain);

            // 顶部 左侧
            _breadcrumbMenu.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_breadcrumbMenu);
            _btnHome.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnHome);
            _btnRefresh.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnRefresh);
            _btnCollapseTreeMenu.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnCollapseTreeMenu);

            // 顶部 右侧
            _txtSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_txtSearch);
            _btnSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSearch);
            _btnSetting.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSetting);
            _btnSwithTheme.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwithTheme);
            _btnSwitchLanguage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwitchLanguage);
            _btnMessage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnMessage);
            _avatar.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_avatar);
            _pnlTopBar.Controls.Add(_pnlTopBtnPanel);
            _pnlContent.Controls.Add(_pnlTopBar);
            _pnlContent.Controls.Add(_lblBottomBarContent);
            _gridMain.Controls.Add(_pnlContent);

            // 侧边栏
            _gridSildebar.Span = "100%";
            _pnlSildebar.Controls.Add(_btnSilderSwitchMenu);
            _ucSuperTitle.Dock = DockStyle.Top;
            _ucSuperTitle.ShowTitle = false;
            _pnlSildebar.Controls.Add(_ucSuperTitle);
            _gridSildebar.Controls.Add(_pnlSildebar);
            _gridMain.Controls.Add(_gridSildebar);
        }

        private void SetMainLayoutSideVerticalMenu()
        {
            _gridMain.Span = _silderWidth + " 100%";

            // 内容区域
            _pnlContent.Controls.Add(_tabMain);

            // 顶部 左侧
            _breadcrumbMenu.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_breadcrumbMenu);
            _btnHome.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnHome);
            _btnRefresh.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnRefresh);
            _btnCollapseTreeMenu.Dock = DockStyle.Left;
            _pnlTopBtnPanel.Controls.Add(_btnCollapseTreeMenu);

            // 顶部 右侧
            _txtSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_txtSearch);
            _btnSearch.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSearch);
            _btnSetting.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSetting);
            _btnSwithTheme.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwithTheme);
            _btnSwitchLanguage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnSwitchLanguage);
            _btnMessage.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_btnMessage);
            _avatar.Dock = DockStyle.Right;
            _pnlTopBtnPanel.Controls.Add(_avatar);
            _pnlTopBar.Controls.Add(_pnlTopBtnPanel);
            _pnlContent.Controls.Add(_pnlTopBar);
            _pnlContent.Controls.Add(_lblBottomBarContent);
            _gridMain.Controls.Add(_pnlContent);

            // 侧边栏
            _treeMenu.Dock = DockStyle.Fill;
            _treeMenu.Mode = TMenuMode.Inline;
            _treeMenu.Gap = 10;
            _pnlSildebar.Controls.Add(_treeMenu);
            _ucSuperTitle.Dock = DockStyle.Top;
            _ucSuperTitle.ShowTitle = true;
            _pnlSildebar.Controls.Add(_ucSuperTitle);
            _gridSildebar.Span = "100%";
            _gridSildebar.Controls.Add(_pnlSildebar);
            _gridMain.Controls.Add(_gridSildebar);
        }

        private void InitializeMainLayout()
        {
            this.Controls.Clear();
            _pnlSildebar.Controls.Clear();
            _pnlTopBar.Controls.Clear();
            _pnlContent.Controls.Clear();
            _pnlTopBtnPanel.Controls.Clear();
            _pnlTopMenuCenter.Controls.Clear();

            // 控件状态初始化
            Controls.Add(_gridMain);
        }

        // 初始化控件
        private void InitializeControls()
        {
            // 初始化主面板
            _gridMain = new GridPanel();
            _gridMain.Dock = DockStyle.Fill;
            _gridMain.BackColor = Color.Transparent;

            // 初始化标题
            _ucSuperTitle = new UcSuperTitle();
            _ucSuperTitle.BackColor = Color.Transparent;

            // 初始化内嵌菜单侧边栏
            _treeMenu = new AntdUI.Menu
            {
                Dock = DockStyle.Fill,
                Indent = true,
                Font = new Font("Microsoft YaHei UI", 10F),
                BackColor = Color.Transparent,
                IconRatio = 0.8f,
            };
            _treeMenu.SelectChanged += _treeMenu_SelectChanged;

            // 初始化面包屑导航
            _breadcrumbMenu = new AntdUI.Breadcrumb
            {
                BackColor = Color.Transparent,
                Font = new Font("Microsoft YaHei UI", 10F),
                Width = 200,
                Height = 40
            };

            // 初始化主Tab控件
            _tabMain = new AntdUI.Tabs
            {
                Dock = DockStyle.Fill,
                Font = new Font("Microsoft YaHei UI", 10F),
                Type = TabType.Card2,
                Gap = 20,
                BackColor = ColorTranslator.FromHtml("#eeeeee"),
                Padding = new Padding(20),
                Style = new AntdUI.Tabs.StyleCard() { Closable = true },
            };

            // 初始化侧边栏面板
            _pnlSildebar = new AntdUI.Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(10),
                Margin = new Padding(0),
            };

            // 初始化侧边栏网格
            _gridSildebar = new GridPanel
            {
                Dock = DockStyle.Fill,
                Margin = new Padding(0),
                BackColor = Color.Transparent,
            };

            // 初始化顶部面板
            _pnlTopBar = new AntdUI.Panel
            {
                Dock = DockStyle.Top,
                Height = 60,
                Padding = new Padding(0, 0, 10, 0),
            };

            // 初始化主面板
            _pnlContent = new AntdUI.Panel
            {
                Dock = DockStyle.Fill,
                Margin = new Padding(1, 0, 0, 0),
            };

            // 初始化搜索输入框
            _txtSearch = new AntdUI.Input()
            {
                PlaceholderText = "搜索菜单",
                JoinMode = TJoinMode.Left,
                Size = new Size(140, 40),
                Margin = new Padding(0)
            };

            // 初始化头像控件
            _avatar = new AntdUI.Avatar
            {
                Size = new Size(40, 40),
                Image = Properties.Resources.Avatar,
                Radius = 50
            };

            // 初始化搜索按钮
            _btnSearch = new AntdUI.Button
            {
                Text = "搜索",
                Size = new Size(40, 40),
                Type = TTypeMini.Primary,
                JoinMode = TJoinMode.Right,
            };

            // 初始化菜单折叠按钮
            _btnCollapseTreeMenu = new AntdUI.Button
            {
                IconSvg = "Admin.Menus",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0
            };
            _btnCollapseTreeMenu.Click += _btnCollapseTreeMenu_Click;

            // 初始化刷新按钮
            _btnRefresh = new AntdUI.Button
            {
                IconSvg = "Admin.Refresh",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0
            };

            // 初始化设置按钮
            _btnSetting = new AntdUI.Button
            {
                IconSvg = "Admin.Setting",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0
            };
            _btnSetting.Click += _btnSetting_Click;

            // 初始化切换主题按钮
            _btnSwithTheme = new AntdUI.Button
            {
                IconSvg = "Admin.DarkThemes",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0,
            };
            _btnSwithTheme.Click += _btnSwithTheme_Click;

            // 初始化消息通知按钮
            _btnMessage = new AntdUI.Button
            {
                IconSvg = "Admin.Message",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0
            };

            // 初始化语言切换按钮
            _btnSwitchLanguage = new Dropdown
            {
                IconSvg = "Admin.Language",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0,
            };
            _btnSwitchLanguage.Items.AddRange(new ISelectItem[]
            {
                new SelectItem("中文","Chinese"),
                new SelectItem("English","English"),
                new SelectItem("日本語","Japanese"),
            });
            SetLanguageMode();
            _btnSwitchLanguage.SelectedValueChanged += _btnSwitchLanguage_SelectedValueChanged;

            // 侧边菜单
            _btnSilderSwitchMenu = new Segmented
            {
                Dock = DockStyle.Top,
                Height = 800,
                BackColor = Color.Transparent,
                BackActive = ColorTranslator.FromHtml(ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.BuiltInThemes.PrimaryColor),
                Vertical = true,
                Font = new Font("Microsoft YaHei UI", 10F),
                ForeActive = Color.White,
                IconRatio = 0.8f,
            };
            _btnSilderSwitchMenu.ItemClick += _btnSilderSwitchMenu_ItemClick;

            // logo标题控件
            _lblLogoTitle = new AntdUI.Label
            {
                Text = "超级管理员",
                Font = new Font("Microsoft YaHei UI", 15F, FontStyle.Bold),
                Height = 60,
                Dock = DockStyle.Top,
                BackColor = Color.Transparent,
            };

            // 双列菜单 - 二级菜单
            _treeSencondMenu = new AntdUI.Menu
            {
                Dock = DockStyle.Fill,
                Font = new Font("Microsoft YaHei UI", 10F),
                Indent = true,
                BackColor = Color.Transparent,
                IconRatio = 0.8f,
            };
            _treeSencondMenu.SelectChanged += _treeMenu_SelectChanged;

            // 双列菜单 - 二级菜单面板
            _pnlSencondMenu = new AntdUI.Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(10),
                Margin = new Padding(1, 0, 0, 0),
            };

            // 顶部菜单
            _pnlTopMenuCenter = new CenterPanel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.Transparent,
                CenterVertically = true,
                CenterHorizontally = true,
            };

            // 顶部按钮面板
            _pnlTopBtnPanel = new AntdUI.Panel
            {
                BackColor = Color.Transparent,
                Dock = DockStyle.Fill,
                Padding = new Padding(0, 10, 0, 10)
            };

            // 顶部一级菜单按钮面板 
            _btnSwitchTopFirstMenu = new Segmented
            {
                Dock = DockStyle.Fill,
                BackColor = Color.Transparent,
                Gap = 10,
                IconAlign = TAlignMini.Left,
                IconGap = 0f,
                BackActive = ColorTranslator.FromHtml(ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.BuiltInThemes.PrimaryColor),
                ForeActive = Color.White,
                Font = new Font("Microsoft YaHei UI", 10F),
                IconRatio = 0.8f,
            };
            _btnSwitchTopFirstMenu.SelectIndexChanged += _btnSwitchTopFirstMenu_SelectIndexChanged;

            // 侧边二级菜单选择
            _btnSilderSwitchSecondMenu = new Segmented
            {
                Dock = DockStyle.Fill,
                BackColor = Color.Transparent,
                Gap = 10,
                Vertical = true,
                BackActive = ColorTranslator.FromHtml(ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.BuiltInThemes.PrimaryColor),
                ForeActive = Color.White,
                Font = new Font("Microsoft YaHei UI", 10F),
                IconRatio = 0.8f,
            };
            _btnSilderSwitchSecondMenu.ItemClick += _btnSilderSwitchSecondMenu_ItemClick;

            // 混合双列 - 三级菜单
            _treeThirdMenu = new AntdUI.Menu
            {
                Dock = DockStyle.Fill,
                Font = new Font("Microsoft YaHei UI", 10F),
                Indent = true,
                BackColor = Color.Transparent,
                IconRatio = 0.8f,
            };
            _treeThirdMenu.SelectChanged += _treeMenu_SelectChanged;

            // 混合双列 - 三级菜单面板
            _pnlThirdMenu = new AntdUI.Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(10),
                Margin = new Padding(1, 0, 0, 0),
            };

            // 首页按钮
            _btnHome = new AntdUI.Button
            {
                IconSvg = "Admin.Home",
                Text = "",
                Size = new Size(40, 40),
                Ghost = true,
                IconRatio = 1,
                WaveSize = 0
            };
            _btnHome.Click += _btnHome_Click;

            // 底栏
            _lblBottomBarContent = new AntdUI.Label
            {
                Text = "Super Admin",
                TextAlign = ContentAlignment.MiddleCenter,
                Dock = DockStyle.Bottom,
                BackColor = Color.Transparent,
                ForeColor = Color.Gray,
                Font = new Font("Microsoft YaHei UI", 10F),
                Height = 30
            };
        }

        private void SetLanguageMode()
        {
            string lang = "Chinese";
            switch (ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language)
            {
                case LanguageType.English:
                    lang = "English";
                    break;
                case LanguageType.Japanese:
                    lang = "Japanese";
                    break;
            }
            _btnSwitchLanguage.SelectedValue = lang;
        }

        private void _btnHome_Click(object? sender, EventArgs e)
        {
            _tabMain.SelectedIndex = 0;
        }

        // 选择语言
        private void _btnSwitchLanguage_SelectedValueChanged(object sender, ObjectNEventArgs e)
        {
            if (_btnSwitchLanguage.SelectedValue != null)
            {
                ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language = Enum.Parse<LanguageType>(_btnSwitchLanguage.SelectedValue.ToString());
            }
            else
            {
                Growl.Warning("请选择一个有效的语言选项");
            }
        }

        private void _btnSwithTheme_Click(object? sender, EventArgs e)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType == TAMode.Light)
            {
                ThemeSettingHelper.Instance.SwitchThemeDrakOrLight(TAMode.Dark);
            }
            else
            {
                ThemeSettingHelper.Instance.SwitchThemeDrakOrLight(TAMode.Light);
            }
            InitializeBtnSetThemeIconSvg();
        }

        private void _btnSilderSwitchSecondMenu_ItemClick(object sender, SegmentedItemEventArgs e)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition != NavigationPosition.MixedDoubleColumnMenu) return;
            // 判断有没有子菜单 如果存在 则展开子菜单
            PermissionBaseModel model = e.Item.Tag as PermissionBaseModel;
            if (model == null) return;
            if (model.HasChild)
            {
                List<PermissionBaseModel> modelList = new List<PermissionBaseModel>();
                MenuList.ForEach(p =>
                {
                    p.PermissionChildren.ForEach(c =>
                    {
                        if (c.Id == model.Id)
                        {
                            modelList = c.PermissionChildren;
                        }
                    });
                });
                AddMenus(modelList, _treeThirdMenu);
                _pnlThirdMenu.Controls.Clear();
                _pnlThirdMenu.Controls.Add(_treeThirdMenu);
                _pnlThirdMenu.Controls.Add(_lblLogoTitle);
                _silderWidth = Convert.ToInt32(_silderOnlyMentBtn) + Convert.ToInt32(_silderSecondColumn) + "";
                _gridSildebar.Span = _silderOnlyMentBtn + " " + _silderSecondColumn;
                _gridSildebar.Controls.Clear();
                _gridSildebar.Controls.Add(_pnlThirdMenu);
                _gridSildebar.Controls.Add(_pnlSildebar);
                _gridMain.Span = _silderWidth + " 100%";
            }
            else
            {
                // 如果没有子菜单 则直接跳转到对应的页面
                if (!ExsitViews(model.Path, out Control view)) return;
                // 如果已经存在该页面 则不再添加
                if (_tabMain.Pages.Any(p => p.Tag is PermissionBaseModel pm && pm.Id == model.Id))
                {
                    _tabMain.SelectedIndex = _tabMain.Pages.FindIndex(p => p.Tag is PermissionBaseModel pm && pm.Id == model.Id);
                }
                else
                {
                    // 如果不存在该页面 则添加到Tab中
                    AddPages(model, view);
                }
                _breadcrumbMenu.Items.Clear();
                SetBreadcrumb(model.Id);
                _gridSildebar.Span = _silderOnlyMentBtn;
                _silderWidth = _silderOnlyMentBtn;
                _gridSildebar.Controls.Remove(_pnlThirdMenu);
                _gridMain.Span = _silderOnlyMentBtn + " 100%";
            }
            InitializeThemeSetting();
        }

        // 折叠树形菜单按钮点击事件
        private void _btnCollapseTreeMenu_Click(object? sender, EventArgs e)
        {
            if (_gridMain.Controls.Contains(_gridSildebar))
            {
                _isCollapseTreeMenu = true;
                _gridMain.Controls.Remove(_gridSildebar);
                _gridMain.Span = "100%";
            }
            else
            {
                _isCollapseTreeMenu = false;
                _gridMain.Controls.Add(_gridSildebar);
                _gridMain.Span = _silderWidth + " 100%";
            }
        }

        // 添加菜单
        private void AddMenus(List<PermissionBaseModel> modelList, AntdUI.Menu treeMenu)
        {
            treeMenu.Items.Clear();
            foreach (var menu in modelList)
            {
                var it = new AntdUI.MenuItem(menu.Name) { IconSvg = menu.Icon, Expand = menu.IsExpanded, Tag = menu };
                if (menu.HasChild) AddSub(it, menu.PermissionChildren);
                treeMenu.Items.Add(it);
            }
        }

        private void AddPages(PermissionBaseModel model, Control view)
        {
            try
            {
                if (_tabMain.Pages.Count == ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.MaximumNumberOfTagPages)
                {
                    AntdUI.Message.error(this, $"已经超出最大标签数：【{ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Tabs.MaximumNumberOfTagPages}】，如果想要新增，请到偏好设置中设置");
                    return;
                }
                AntdUI.TabPage page = new AntdUI.TabPage();
                page.Text = model.Name;
                page.IconSvg = model.Icon;
                page.Tag = model;
                page.ReadOnly = !model.IsCanClose;
                page.Controls.Add(view);
                _tabMain.Pages.Add(page);
                _tabMain.SelectedIndex = _tabMain.Pages.Count - 1;
            }
            catch (Exception ex)
            {
                AntdUI.Message.error(this, ex.Message);
            }
        }

        private void _btnSwitchTopFirstMenu_SelectIndexChanged(object sender, IntEventArgs e)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition != NavigationPosition.MixedDoubleColumnMenu) return;
            PermissionBaseModel model = _btnSwitchTopFirstMenu.Items[e.Value].Tag as PermissionBaseModel;
            if (model == null) return;
            this.SuspendLayout();
            _btnSilderSwitchSecondMenu.Items.Clear();
            // 判断有没有子菜单
            List<PermissionBaseModel> secondMenus = AllMenuModelList.Where(m => m.ParentId == model.Id).ToList();
            if (secondMenus.Count > 0)
            {
                foreach (var menu in secondMenus)
                {
                    _btnSilderSwitchSecondMenu.Items.Add(new SegmentedItem
                    {
                        Text = menu.Name,
                        IconSvg = menu.Icon,
                        Tag = menu,
                    });
                }
                _silderWidth = _silderOnlyMentBtn;
                if (_gridMain.Span != _silderOnlyMentBtn + " 100%")
                {
                    _gridMain.Span = _silderOnlyMentBtn + " 100%";
                    _gridMain.Controls.Add(_gridSildebar);
                }
            }
            else
            {
                _gridMain.Controls.Remove(_gridSildebar);
                _gridMain.Span = "100%";
            }
            this.ResumeLayout();
        }

        private void _treeMenu_SelectChanged(object sender, MenuSelectEventArgs e)
        {
            PermissionBaseModel menu = (PermissionBaseModel)e.Value.Tag;
            if (string.IsNullOrEmpty(menu.Path)) return;
            // 先判断是否已经打开过
            var tab = _tabMain.Pages.FirstOrDefault(p => p.Tag == menu);
            if (tab == null)
            {
                // 获取选中的菜单
                if (!ExsitViews(menu.Path, out Control view)) return;
                AddPages(menu, view);
            }
            else
            {
                _tabMain.SelectedIndex = _tabMain.Pages.IndexOf(tab);
            }
            _breadcrumbMenu.Items.Clear();
            SetBreadcrumb(menu.Id);
        }

        private void _btnSilderSwitchMenu_ItemClick(object sender, SegmentedItemEventArgs e)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Layout.NavigationPosition == NavigationPosition.VerticalDoubleColumnMenu)
            {
                // 判断有没有子菜单 如果存在 则展开子菜单
                PermissionBaseModel model = e.Item.Tag as PermissionBaseModel;
                if (model == null) return;
                if (model.HasChild)
                {
                    List<PermissionBaseModel> modelList = MenuList.Where(m => m.Id == model.Id).FirstOrDefault().PermissionChildren;
                    AddMenus(modelList, _treeSencondMenu);
                    _pnlSencondMenu.Controls.Clear();
                    _pnlSencondMenu.Controls.Add(_treeSencondMenu);
                    _pnlSencondMenu.Controls.Add(_lblLogoTitle);
                    _gridSildebar.Span = _silderOnlyMentBtn + " " + _silderSecondColumn;
                    _silderWidth = Convert.ToInt32(_silderOnlyMentBtn) + Convert.ToInt32(_silderSecondColumn) + "";
                    _gridSildebar.Controls.Clear();
                    _gridSildebar.Controls.Add(_pnlSencondMenu);
                    _gridSildebar.Controls.Add(_pnlSildebar);
                    _gridMain.Span = _silderWidth + " 100%";
                }
                else
                {
                    // 如果没有子菜单 则直接跳转到对应的页面
                    if (!ExsitViews(model.Path, out Control view)) return;
                    // 如果已经存在该页面 则不再添加
                    if (_tabMain.Pages.Any(p => p.Tag is PermissionBaseModel pm && pm.Id == model.Id))
                    {
                        _tabMain.SelectedIndex = _tabMain.Pages.FindIndex(p => p.Tag is PermissionBaseModel pm && pm.Id == model.Id);
                    }
                    else
                    {
                        // 如果不存在该页面 则添加到Tab中
                        AddPages(model, view);
                    }
                    _breadcrumbMenu.Items.Clear();
                    SetBreadcrumb(model.Id);
                    _gridSildebar.Span = _silderOnlyMentBtn;
                    _silderWidth = _silderOnlyMentBtn;
                    _gridSildebar.Controls.Remove(_pnlSencondMenu);
                    _gridMain.Span = _silderWidth + " 100%";
                }
                InitializeThemeSetting();
            }
        }

        private void InitHomePage()
        {
            _homeMneu = AllMenuModelList.Where(m => m.Id == 20001).FirstOrDefault(); // 工作台 或者首页 必须Id == 20001
            if (!ExsitViews(_homeMneu.Path, out Control view)) return;
            _homeMneu.IsCanClose = false; // 首页不允许关闭
            AddPages(_homeMneu, view);
            SetBreadcrumb(_homeMneu.Id);
            _treeMenu.Items.ForEach(p => { p.Select = false; p.Sub.ForEach(c => c.Select = false); });
            SetMenuTracking(_homeMneu.Id);
        }

        // 自动选中TreeMenu
        private void SetMenuTracking(int menuId)
        {
            // 循环菜单列表找到对应的菜单项
            foreach (MenuItem parent in _treeMenu.Items)
            {
                if (parent.Tag is PermissionBaseModel pModel && pModel.Id == menuId)
                {
                    parent.Expand = true;
                    parent.Select = true;
                    break;
                }
                foreach (MenuItem child in parent.Sub)
                {
                    if (child.Tag is PermissionBaseModel cModel && cModel.Id == menuId)
                    {
                        child.Select = true;
                        child.Expand = true;
                        break;
                    }
                }
            }
            PermissionBaseModel parentModel = AllMenuModelList.Where(m => m.Id == menuId).FirstOrDefault();
            if (parentModel?.ParentId != 0)
            {
                SetMenuTracking(parentModel.ParentId);
            }
        }
        private void _tabMain_SelectedIndexChanged(object sender, IntEventArgs e)
        {
            PermissionBaseModel model = _tabMain.Pages[_tabMain.SelectedIndex].Tag as PermissionBaseModel;
            if (model != null)
            {
                _breadcrumbMenu.Items.Clear();
                SetBreadcrumb(model.Id);
                _treeMenu.Items.ForEach(p => { p.Select = false; p.Sub.ForEach(c => c.Select = false); });
                SetMenuTracking(model.Id);
            }
        }
        private void InitializeSettingDrawer()
        {
            // 设置抽屉
            _ucMainDrawerSetting = new UcMainDrawerSetting() { Width = 400 };
        }



        /// <summary>
        /// 加载本地权限列表
        /// </summary>
        private void LoadLocalPermissionList()
        {
            List<int> roleIdList = new List<int>();
            foreach (var userRole in Global.AppContext.Instance.LoginUserModel?.UserRoles)
            {
                if (userRole.Role.IsActive == 0) roleIdList.Add(userRole.RoleId);
            }
            AllPermissionList = (List<PermissionBaseModel>)_permissionService.GetPermissionsByUserRoleIds(roleIdList).ToBaseModels();
            AllMenuModelList = AllPermissionList.Where(a => a.Type != 2).ToList(); // 获取所有的菜单权限
            if (AllMenuModelList.Count == 0)
            {
                AntdUI.Message.error(this, $"此账号【{Global.AppContext.Instance.LoginUserModel.UserIdAndUserName}】没有任何菜单权限，请联系管理员分配权限");
                return;
            }
            // 层级设置
            MenuList = SetPermissionList(AllMenuModelList, 0);
            InitializTreeMenu(MenuList);
            // 获取所有的按钮权限
            List<PermissionBaseModel> buttonRoles = AllPermissionList.Where(a => a.Type == 2).ToList();
            foreach (var buttonRole in buttonRoles)
            {
                Global.AppContext.Instance.AuthPermissionList.Add(buttonRole.Permissionkey);
            }
        }
        /// <summary>
        /// 初始化树形菜单
        /// </summary>
        /// <param name="menuList"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void InitializTreeMenu(List<PermissionBaseModel> menuList)
        {
            // 初始化树状菜单
            _treeMenu.Items.Clear();
            // 双列菜单 - 左侧菜单
            _btnSilderSwitchMenu.Items.Clear();
            // 混合双列 头部菜单
            _btnSwitchTopFirstMenu.Items.Clear();
            AddMenus(menuList, _treeMenu);
            foreach (var menu in menuList)
            {
                // 双列菜单 - 左侧菜单
                _btnSilderSwitchMenu.Items.Add(new SegmentedItem
                {
                    Text = menu.Name,
                    IconSvg = menu.Icon,
                    Tag = menu
                });

                // 混合双列 头部菜单
                _btnSwitchTopFirstMenu.Items.Add(new SegmentedItem
                {
                    Text = menu.Name,
                    IconSvg = menu.Icon,
                    Tag = menu
                });
            }
            _btnSilderSwitchMenu.SelectIndex = 0;
            _btnSwitchTopFirstMenu.SelectIndex = 0;
        }
        /// <summary>
        /// 添加子节点到树形菜单
        /// </summary>
        /// <param name="it"></param>
        private void AddSub(MenuItem it, List<PermissionBaseModel> menuList)
        {
            var subList = new List<AntdUI.MenuItem>();
            foreach (var menu in menuList)
            {
                var its = new AntdUI.MenuItem(menu.Name) { IconSvg = menu.Icon, Expand = menu.IsExpanded, Tag = menu };
                if (menu.HasChild) AddSub(its, menu.PermissionChildren);
                subList.Add(its);
            }
            it.Sub.AddRange(subList);
        }
        /// <summary>
        /// 构架权限树
        /// </summary>
        /// <param name="sourceModel"></param>
        /// <param name="parent"></param>
        public List<PermissionBaseModel> SetPermissionList(List<PermissionBaseModel> sourceModel, int parent = 0)
        {
            List<PermissionBaseModel> permissionModels = new List<PermissionBaseModel>();
            List<PermissionBaseModel> list = sourceModel.Where(s => s.ParentId == parent).ToList();
            foreach (var l in list)
            {
                permissionModels.Add(l);
                foreach (var menu in permissionModels)
                {
                    menu.PermissionChildren = GetChildren(sourceModel, menu.Id);
                }
            }
            return permissionModels;
        }
        /// <summary>
        /// 循环获取嵌套菜单
        /// </summary>
        /// <param name="sourceModel"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        private List<PermissionBaseModel> GetChildren(List<PermissionBaseModel> sourceModel, int parentId)
        {
            var children = sourceModel.Where(m => m.ParentId == parentId).ToList();
            foreach (var child in children)
            {
                child.PermissionChildren = GetChildren(sourceModel, child.Id);
            }
            return new List<PermissionBaseModel>(children);
        }
        private void _btnSetting_Click(object? sender, EventArgs e)
        {
            InitializeSettingDrawer();
            Drawer.open(this, _ucMainDrawerSetting);
        }
        /// <summary>
        /// 设置面包屑导航
        /// </summary>
        /// <param name="allMenuModelList"></param>
        /// <param name="menuId"></param>
        private void SetBreadcrumb(int menuId)
        {
            // 获取当前的菜单
            PermissionBaseModel model = AllMenuModelList.FirstOrDefault(m => m.Id == menuId);
            BreadcrumbItem item = new BreadcrumbItem
            {
                Text = model.Name,
                Tag = model,
            };
            if (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.Breadcrumb.DisplayBreadcrumbIcon)
            {
                item.IconSvg = model.Icon;
            }
            _breadcrumbMenu.Items.Insert(0, item);
            if (model.ParentId != 0)
            {
                SetBreadcrumb(model.ParentId);
            }
        }
        /// <summary>
        /// 判断是否存在页面
        /// </summary>
        /// <param name="viewPath"></param>
        /// <param name="view"></param>
        /// <param name="_namespace"></param>
        /// <returns></returns>
        private bool ExsitViews(string viewPath, out Control view, string _namespace = "Super.Admin.Views.")
        {
            view = null;
            string defualt403View = _namespace + "Page.FrmDefultPage403";
            Type type = Type.GetType(_namespace + viewPath);
            if (type == null)
            {
                type = Type.GetType(defualt403View);
                if (type == null)
                {
                    AntdUI.Message.error(this, $"未找到视图：【{viewPath}】");
                    return false;
                }
            }
            try
            {
                // 从Autofac容器尝试解析实例
                view = (Control)Program.Container.Resolve(type);
                if (view is BaseUserControl baseUC)
                {
                    baseUC.ParentForm = this;
                }
                view.Dock = DockStyle.Fill;
                return true;
            }
            catch (Exception ex)
            {
                AntdUI.Message.error(this, ex.Message);
                return false;
            }
        }
    }
}
